package com.clickpaas.materialsprocurement.service.Impl;

import com.bizcloud.ipaas.t0ba0ba6afb694026b6b4e4e048af2b43.d20210202135416.model.UnitDTOResponse;
import com.clickpaas.materialsprocurement.dao.UnitDao;
import com.clickpaas.materialsprocurement.entity.UnitEntity;
import com.clickpaas.materialsprocurement.service.UnitService;
import com.clickpaas.materialsprocurement.utils.DataInfoUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
@Slf4j
public class UnitServiceImpl implements UnitService {
    @Resource
    private UnitDao unitDao;
    /**
     * 获取单位数据
     *
     * @param unitEntity
     * @return
     */
    @Override
    public List<UnitDTOResponse> getUnitInfo(UnitEntity unitEntity) {

        List<UnitDTOResponse> reUnitList;
        try {
            /**
             * 入参为空,不查询
             */
            if (null == unitEntity || DataInfoUtil.isAllFieldNull(unitEntity)){
                return null;
            }else {
                reUnitList = unitDao.getUnitByCondtion(unitEntity);
            }
        } catch (Exception e) {
            log.info("入参对象异常,请检查：【{}】,报错信息：【{}】",unitEntity,e);
            return null;
        }
        if (null != reUnitList && reUnitList.size()>0){
            return reUnitList;
        }
        return null;
    }

    /**
     * 单位数据转换为bean
     *
     * @param list
     * @return
     */
    @Override
    public List<UnitEntity> unitDataConver(List<UnitDTOResponse> list) {
        return DataInfoUtil.castListCopy(list,UnitDTOResponse.class,UnitEntity.class);
    }
}
